﻿using Logistics.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsAutoBill
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {   
            timer1.Enabled = true;
            button1.Enabled = false;
            button5.Enabled = true;
        }

        /// <summary>
        /// 获取Get/POST请求结果(只包含URL数据请求)
        /// </summary>
        /// <param name="requestUrl">请求地址</param>
        /// <param name="timeout">超时时间</param>
        /// <param name="encoding">解码方式</param>
        /// <param name="method">请求方法</param>
        /// <returns>返回请求结果</returns>
        public static string GetWebResponse(string requestUrl, int timeout, string encoding, string method = "GET")
        {
            string response = string.Empty;
            try
            {
                if (!string.IsNullOrEmpty(requestUrl))
                {
                    HttpWebRequest myRequest = WebRequest.Create(requestUrl) as HttpWebRequest;
                    myRequest.ServicePoint.Expect100Continue = false;
                    myRequest.ServicePoint.UseNagleAlgorithm = false;
                    myRequest.Headers.Clear();  //清除http请求头信息
                    myRequest.Timeout = timeout;   //超时时间
                    myRequest.Method = method;  //默认GET方式提交
                    myRequest.ContentType = "application/x-www-form-urlencoded";
                    HttpWebResponse myResponse = myRequest.GetResponse() as HttpWebResponse;
                    using (StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding(encoding)))
                    {
                        response = reader.ReadToEnd();
                    }
                }
            }
            catch { }
            
            return response;
        }//end method
        private void timer1_Tick(object sender, EventArgs e)
        {
            string strurl = "http://api.qy.7yunbao.com:801/api/AutoBid/GetAutoStartBillList";
            //string strurl = "http://192.168.211.105:8081/api/AutoBid/GetAutoStartBillList";
            
            //string strurl = "http://localhost:56981/api/AutoBid/GetAutoStartBillList";
           string str= GetWebResponse(strurl, 30000, "utf-8");
           //string strurl1 = "http://localhost:56981/api/AutoBid/GetAutoEndBillList";
          string strurl1 = "http://api.qy.7yunbao.com:801/api/AutoBid/GetAutoEndBillList";
           //string strurl1 = "http://192.168.211.105:8081/api/AutoBid/GetAutoEndBillList";
          string str1 = GetWebResponse(strurl1, 30000, "utf-8");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            BidBaseService bidser = new BidBaseService();
           var mum= bidser.GetUpdateBidBaseList();
           MessageBox.Show(mum.ToString());
        }

        private void button3_Click(object sender, EventArgs e)
        {
            ReportBidService report1 = new ReportBidService();
           var mum= report1.OperatReportList();
            MessageBox.Show(mum.ToString());
        }

        private void button4_Click(object sender, EventArgs e)
        {
            WuLiuCompanyService comapany = new WuLiuCompanyService();
           int nu = comapany.OpeartWuliuList();
           MessageBox.Show(nu.ToString());
        }

        private void button5_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            button1.Enabled = true;
            button5.Enabled = false;
        }
    }
}
